//
//  NSData+ext.m
//  MMTest
//
//  Created by liujianlong on 2022/9/21.
//

#import "NSData+ext.h"

@implementation NSData (ext)
- (NSString *)mac{
    if (self.length == 0) {
        return @"";
    }
    Byte *chRevCP = (Byte*)[self bytes];
    
    NSString *string = [NSString stringWithFormat:@"%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",chRevCP[1],chRevCP[0],chRevCP[2],chRevCP[3],chRevCP[4],chRevCP[5],chRevCP[6],chRevCP[7]];
    //        self.deviceName = advertisementData[@"kCBAdvDataLocalName"];
    
    NSString *macStr = string;
    NSString *resultStr = [NSString stringWithFormat:@"%@%@:%@%@:%@%@:%@%@:%@%@:%@%@",
                           [macStr substringWithRange:NSMakeRange(4, 1)],[macStr substringWithRange:NSMakeRange(5, 1)],
                           [macStr substringWithRange:NSMakeRange(6, 1)],[macStr substringWithRange:NSMakeRange(7, 1)],
                           [macStr substringWithRange:NSMakeRange(8, 1)],[macStr substringWithRange:NSMakeRange(9, 1)],
                           [macStr substringWithRange:NSMakeRange(10, 1)],[macStr substringWithRange:NSMakeRange(11, 1)],
                           [macStr substringWithRange:NSMakeRange(12, 1)],[macStr substringWithRange:NSMakeRange(13, 1)],
                           [macStr substringWithRange:NSMakeRange(14, 1)],[macStr substringWithRange:NSMakeRange(15, 1)]];
    return  resultStr;
}
@end
